"""
    链表的逆序输出
"""


class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


def printListFromTailToHead(listNode):
    # write code here
    value_list = []
    if listNode is None:
        return value_list
    while listNode.next is not None:
        value_list.append(listNode.val)
        listNode = listNode.next
    value_list.append(listNode.val)
    return value_list[::-1]


node1 = ListNode(1)
node2 = ListNode(2)
node3 = ListNode(3)
node4 = ListNode(4)
node1.next = node2
node2.next = node3
node3.next = node4
node4.next = None

print(printListFromTailToHead(node1))
